//
//  InterpretationTwoViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/7/8.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "InterpretationTwoViewController.h"
#import "PayEvaluationViewController.h"
@interface InterpretationTwoViewController ()

@end

@implementation InterpretationTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    ////NSLog(@"啊啊啊啊啊啊%@",self.activityId);
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    //设置导航栏头文字
    self.navigationItem.title = @"同城解读";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#44afd7" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    //自定义左右按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turntolast)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self subView];
    //注册通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:) name:@"tongzhi" object:nil];
    
}
-(void)subView{
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];

    NSDictionary *param3= @{@"userId": ID,@"activityId":self.activityId,@"typeId":@"1"};
    
    [UserDAL getOutDoorActivityDetailsWithParams:param3 withBlock:^(NSDictionary *data, NSError *error) {
        
        
        //NSLog(@"%@",data);
        if (data.count!=0) {

            [MBProgressHUD hideHUDForView:self.view animated:YES];

        NSString * imageStr = [data objectForKey:@"imageURL"];
        NSString * activityName = [data objectForKey:@"activityName"];
        NSString * amountJoined = [data objectForKey:@"amountJoined"];
        NSString * type = [data objectForKey:@"type"];
        NSString * zone = [data objectForKey:@"zone"];
        NSString * timeStamp = [data objectForKey:@"timeStamp"];
        NSString * howlong = [data objectForKey:@"howlong"];
        NSString * brief = [data objectForKey:@"brief"];
        NSString * status = [data objectForKey:@"status"];

        
        
        ////NSLog(@"%@,%@,%@,%@，%@,%@,%@",activityName,amountJoined,type,zone,timeStamp,howlong,brief);
        
        
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, NavbarHight, SCREEN_WIDTH, SCREEN_HEIGHT/4.4)];
        [_imageView sd_setImageWithURL:[NSURL  URLWithString:imageStr] placeholderImage:nil];
        [self.view addSubview:_imageView];
        
        
        
        UIView *higt = [[UIView alloc]initWithFrame:CGRectMake(0, NavbarHight+SCREEN_HEIGHT/4.4+1, SCREEN_WIDTH, 1)];
        higt.backgroundColor = UIColorWithRGBA(187, 187, 187, 1);
        [self.view addSubview:higt];
        
        cityType = [self labelCreationUsingFrame:CGRectMake(15, NavbarHight+SCREEN_HEIGHT/4.4+1, 100, 30) andFont:[UIFont systemFontOfSize:13] andText:@"活动介绍:"andAlignMent:NSTextAlignmentLeft];


//            other  = [[UILabel alloc]initWithFrame:CGRectMake(5, NavbarHight+SCREEN_HEIGHT/4.4+30, SCREEN_WIDTH-10, 30)];
//            NSString * tstring =@"11111111aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
//            other.numberOfLines =0;
//            UIFont * tfont = [UIFont systemFontOfSize:13];
//            other.font = tfont;
//            other.lineBreakMode =NSLineBreakByTruncatingTail ;
//            other.text = tstring ;
//            [other setBackgroundColor:[UIColor whiteColor]];
//            [self.view addSubview:other];
//            
//            CGSize size =CGSizeMake(SCREEN_WIDTH-10,MAXFLOAT);
//            NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
//            CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
//            other.frame =CGRectMake(5,5, actualsize.width, actualsize.height);
//
    
        
        _tBtn.backgroundColor = UIColorWithRGBA(237, 236, 241, 1);
        _oBtn.backgroundColor = UIColorWithRGBA(255, 255, 255, 1);
            
        _labView1 = [[UIImageView alloc]init];
            if (IS_IPHONE_4_OR_LESS) {
                
                _labView1.frame = CGRectMake(5, NavbarHight+SCREEN_HEIGHT/1.7-50-30, SCREEN_WIDTH-10, SCREEN_HEIGHT-(NavbarHight+SCREEN_HEIGHT/1.7-50+3)-10+30);

                
            } else {
                
                _labView1.frame = CGRectMake(5, NavbarHight+SCREEN_HEIGHT/1.7-50-30, SCREEN_WIDTH-10, SCREEN_HEIGHT-(NavbarHight+SCREEN_HEIGHT/1.7-50+3)-10);

                
                
            }
        _labView1.image = [UIImage imageNamed:@"同城解读详情页线框@2x.png.png"];
        _labView1.userInteractionEnabled=YES;
        [self.view addSubview:_labView1];
            
            
        timeLab = [self labelCreationUsingFrame:CGRectMake(30, 15, SCREEN_WIDTH-24, 20) andFont:[UIFont systemFontOfSize:14] andText:[NSString stringWithFormat:@"时间:%@",timeStamp] andAlignMent:NSTextAlignmentLeft];
            
        longLab = [self labelCreationUsingFrame:CGRectMake(30, 15+20+15, SCREEN_WIDTH-24, 20) andFont: [UIFont systemFontOfSize:14] andText:[NSString stringWithFormat:@"时长:%@",howlong] andAlignMent:NSTextAlignmentLeft];
            
        cityLab = [self labelCreationUsingFrame:CGRectMake(30, 15+70, SCREEN_WIDTH-24, 20) andFont:[UIFont systemFontOfSize:14] andText: [NSString stringWithFormat:@"会场:%@",zone] andAlignMent:NSTextAlignmentLeft];
            
        numLab = [self labelCreationUsingFrame:CGRectMake(30, 15+105, SCREEN_WIDTH-24, 20) andFont:[UIFont systemFontOfSize:14] andText:[NSString stringWithFormat:@"人数:%@",amountJoined] andAlignMent:NSTextAlignmentLeft];
            
            if ([self.dont  isEqual: @"1"]) {
                
                
            } else {
                
                
                UIButton * nowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                nowBtn.frame = CGRectMake(80, 15+105+30, SCREEN_WIDTH-160, 40);
//                nowBtn.backgroundColor = UIColorWithRGBA(255, 117, 118, 1);
                [nowBtn addTarget:self action:@selector(babys) forControlEvents:UIControlEventTouchUpInside];
                [nowBtn setTitle:@"立即报名" forState:UIControlStateNormal];
                [nowBtn setBackgroundImage:[UIImage imageNamed:@"red@2x"] forState:UIControlStateNormal];
                [nowBtn setBackgroundImage:[UIImage imageNamed:@"redScl@2x"] forState:UIControlStateHighlighted];
                [nowBtn setTintColor:[UIColor whiteColor]];
                nowBtn.layer.cornerRadius = 8;
                
                if ([status integerValue] == 1) {
                    [_labView1 addSubview:nowBtn];
                    
                }else{
                    
                    [JKAlert showMessage:@"提示" message:@"您已参加活动"];
                    
                    [nowBtn removeFromSuperview];
                    
                }

                
                
            }
            
        [self.view addSubview:_labView1];
        
        
        UILabel * testlable = [[UILabel alloc]initWithFrame:CGRectMake(10,20,200,20)];
        
        NSString * tstring =  brief;

        testlable.numberOfLines =0;
        
        UIFont * tfont = [UIFont systemFontOfSize:11];
        
        testlable.font = tfont;
        
        testlable.lineBreakMode =NSLineBreakByTruncatingTail ;
        
        testlable.text = tstring ;
        [testlable setBackgroundColor:[UIColor whiteColor]];
        
        [self.view addSubview:testlable];
        
        
        CGSize size =CGSizeMake(SCREEN_WIDTH-20,SCREEN_HEIGHT/3.5-10);
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
        
        
        CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
        testlable.frame =CGRectMake(10,NavbarHight+SCREEN_HEIGHT/4.4+32, actualsize.width, actualsize.height);
        
        [self.view addSubview:testlable];

        }else{
            
            alert(@"暂无同城解读详情信息");
            
            
        }
        
    }];
    

    
    
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    
    
    NSString *msg = [[NSString alloc] initWithFormat:@"您点击的是第%d个按钮!",buttonIndex];
    ////NSLog(@"msg:%@",msg);
    if (buttonIndex == 0) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
        ////NSLog(@"1111111");
        
    }else if(buttonIndex == 1){
        
        
        ////NSLog(@"2222222");
        
        
    }
    
    
}


/**lable*/
-(UILabel *) labelCreationUsingFrame:(CGRect) frame andFont:(UIFont *) font andText:(NSString *) text andAlignMent:(NSTextAlignment) alignment{
    
    
    UILabel * numLabs = [[UILabel alloc]initWithFrame:frame];
    numLabs.text = text;
    numLabs.font = font;
    numLabs.textAlignment = alignment;
    if (font == [UIFont systemFontOfSize:14]) {
        
        [_labView1 addSubview:numLabs];

        
    }else{
        
        [self.view addSubview:numLabs];
        
    }
    return numLabs;
    
    
}

-(void)turntolast{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}



- (void)tongzhi:(NSNotification *)text{
    ////NSLog(@"%@",text.userInfo[@"textOne"]);
    ////NSLog(@"－－－－－接收到通知------");
    
    
    
}




-(void)babys{
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];

    NSDictionary *param3= @{@"userId":ID ,@"activityId":self.activityId,@"typeId":@"2"};
    [UserDAL getOutDoorActivityDetailsWithParams:param3 withBlock:^(NSDictionary *data, NSError *error) {
        
        
        //        ////NSLog(@"%@",data);
        
        
        NSString * zone = [data objectForKey:@"zone"];
        NSString * timeStamp = [data objectForKey:@"timeStamp"];
        NSString * price = [data objectForKey:@"price"];

        
        
        PayEvaluationViewController * pay = [[PayEvaluationViewController alloc]init];
        pay.time = timeStamp;
        pay.type = zone;
        pay.price = price;
        pay.activityId = self.activityId;
        pay.name = self.name;
        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:pay];
        [self presentViewController:nav animated:YES completion:nil];
        
        
    }];
    


    
    
    
}

-(void)baby{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
